package org.lql.chaos.rocketmq.callback;

import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author: liangqinglong
 * @date: 2025-08-16 21:10
 * @description:
 **/
public abstract class AbstractSendCallback implements SendCallback {

	private static final Logger log = LoggerFactory.getLogger(AbstractSendCallback.class);

	@Override
	public void onSuccess(SendResult sendResult) {
		log.info("消息发送成功：{}", sendResult);
		doOnSuccess(sendResult);
	}

	@Override
	public void onException(Throwable throwable) {
		log.error("消息发送异常：", throwable);
		doOnException(throwable);
	}

	/**
	 * 子类实现具体的成功处理逻辑
	 */
	protected abstract void doOnSuccess(SendResult sendResult);

	/**
	 * 子类实现具体的异常处理逻辑
	 */
	protected abstract void doOnException(Throwable throwable);
}
